package cn.four.hqServer.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	
	/** 传入开始与结束时间，计算时间差
	 * @param date1 开始时间
	 * @param date2 结束时间
	 * @return double 小时
	 *  */
	public static double shijiancha(String date1, String date2) {
//		System.out.println("date1" + date1 + "date1");
//		System.out.println("date2" + date2 + "date2");
		Calendar dateOne = Calendar.getInstance(), dateTwo = Calendar.getInstance();
		dateOne.setTime(Stringtodatetime(date2)); // 设置结束时间
		dateTwo.setTime(Stringtodatetime(date1)); // 设置开始时间
		long timeOne = dateOne.getTimeInMillis();
		long timeTwo = dateTwo.getTimeInMillis();
		double minute = (timeOne - timeTwo) / (1000 * 60);// 转化minute
//		System.out.println("相隔" + minute + "分钟");
		double hours = minute / 60;
//		System.out.println("相隔" + hours + "小时");
		return hours;
	}
	
	/** 传入开始与结束时间，计算时间差
	 * @param date1 开始时间
	 * @param date2 结束时间
	 * @return double 分钟
	 *  */
	public static double shijianchamin(String date1, String date2) {
		System.out.println("date1" + date1 + "date1");
		System.out.println("date2" + date2 + "date2");
		Calendar dateOne = Calendar.getInstance(), dateTwo = Calendar.getInstance();
		dateOne.setTime(Stringtodatetime(date2)); // 设置结束时间
		dateTwo.setTime(Stringtodatetime(date1)); // 设置开始时间
		long timeOne = dateOne.getTimeInMillis();
		long timeTwo = dateTwo.getTimeInMillis();
		double minute = (timeOne - timeTwo) / (1000 * 60);// 转化minute
		System.out.println("相隔" + minute + "分钟");
	
		return minute;
	}
	
	/** 传入开始与结束时间，计算时间差
	 * @param date1 开始时间
	 * @param date2 结束时间
	 * @return double 分钟
	 *  */
	public  static double dateshijianchamin(Date date1, Date date2) {
		System.out.println("date1" + date1 + "date1");
		System.out.println("date2" + date2 + "date2");
		Calendar dateOne = Calendar.getInstance(), dateTwo = Calendar.getInstance();
		dateOne.setTime(date2); // 设置结束时间
		dateTwo.setTime(date1); // 设置开始时间
		long timeOne = dateOne.getTimeInMillis();
		long timeTwo = dateTwo.getTimeInMillis();
		double minute = (timeOne - timeTwo) / (1000 * 60);// 转化minute
		System.out.println("相隔" + minute + "分钟");
	
		return minute;
	}
	public static Date Stringtodatetime(String strdate) {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
			try {
				date = sdf.parse(strdate);
			} catch (java.text.ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		return date;
	}
	
	
	
}
